package com.jetgege.loginmvp.presenter;

import com.jetgege.loginmvp.view.ILoginView;
import com.jetgege.loginmvp.other.IOnLoginFinishedListener;
import com.jetgege.loginmvp.other.User;
import com.jetgege.loginmvp.model.ILoginModel;
import com.jetgege.loginmvp.model.LoginModelImpl;

/**
 * Created by Administrator on 2018/8/7.
 */

public class LoginPresenterImpl implements ILoginPresenter,IOnLoginFinishedListener {

    private ILoginView loginView;
    private ILoginModel loginModel;

    public LoginPresenterImpl(ILoginView loginView){
        this.loginView = loginView;
        this.loginModel = new LoginModelImpl();
    }

    @Override
    public void validateCredentials(String userName, String password) {
        if (loginView!=null){
            loginView.showProgress();
        }
        loginModel.login(userName,password,this);
    }

    @Override
    public void onDestroy() {
        loginView=null;
    }

    @Override
    public void onError(String error) {
        loginView.loginError(error);
    }

    @Override
    public void onSuccess(User user) {
        loginView.loginSuccess(user);
    }
}
